<%-- 
    Document   : contentlist
    Created on : Apr 25, 2012, 3:02:22 PM
    Author     : acer
--%>

<%@page import="model.ListContentModel"%>
<%@page import="model.PostModel"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="header.jsp"%>
<%@include file="connect.jspf"%>
<%
    PostModel p_model = new PostModel(con);
    ListContentModel listmodel = new ListContentModel(con);
    int last = (request.getParameter("last")!=null)? Integer.parseInt(request.getParameter("last")):0;
    String tag = (request.getParameter("tag")!=null)? request.getParameter("tag"):"";
    String filtermode = (request.getParameter("filtermode")!=null)? request.getParameter("filtermode"):"";
    String sortmode = (request.getParameter("sortmode")!=null)? request.getParameter("sortmode"):"";
    String viewerid = (session.getAttribute("userid")!=null)? session.getAttribute("userid").toString():"0";
    int maxinpage = 4;
%>
	<!-- Body -->
	<div id="bodycontent">
	  <div class="contentcontainer">

		<div class="title-text">
		  <h1>Daftar konten</h1>
		</div>

		<div class = "contentbox">
			<form method="GET" action=list-content.jsp>
				<div class="form-element1">Filter By Tags(pisahkan dengan koma ',')</div>
				<div class="form-element2"><input type="text" name="tag"size="35"/></div>
				<br/>
				<div class="form-element1">Mode Filter</div>
				<div class="form-element2">
					<select name="filtermode">
						<option value="OR">or</option>
						<option value="AND">and</option>
						<option value="NOT">not</option>
					</select>
				</div>
				<br/>
				<div class="form-element1">Sorting Mode</div>
				<div class="form-element2">
					<select name="sortmode">
						<option value="datetime">Time</option>
						<option value="like_count">Likes</option>
						<option value="comment_count">Comments</option>
					</select>
				</div>
				<br/>
				<div class="form-element1"><input class="button" type="submit" value="Filter Now"/></div>
			</form>
		</div> <!-- end of contentbox untuk filter dan sorting-->
	<div class = "contentbox">
		<span>AllTags:</span>
		<div class= "input_tag">
		</div>
		<div class = "tag_list">
                    <%
                        out.println(listmodel.showAllTags());
                    %>
		</div>
	</div>
       <%
            String countquery = listmodel.generateCountListQuery(tag, filtermode, sortmode, last, maxinpage);
            String query = listmodel.generateListQuery(tag, filtermode, sortmode, last, maxinpage);
            if(!countquery.isEmpty() && !query.isEmpty())
            {
                int datarow = listmodel.getResultFromQuery(countquery).getRow();
                out.println(listmodel.listPost(query, Integer.parseInt(viewerid)));
                int lastindex = listmodel.getLastIndex();
            }
            else{
        %>

		<div class="contentbox">
			<span style="color:red">Tag Kosong</span>
		</div>

        <%
            }
           %>

	  </div>
	</div>
	<script type="text/javascript">
	function jlastobject()
	{
		this.value =  <% out.print(last); %>
	}
	var max=0;
	var jlast = new jlastobject();
	var jtag = <%out.print((tag.isEmpty())? "\"\"":tag);%>;
	var jfilter = <%out.print((filtermode.isEmpty())? "\"\"":filtermode);%>;
	var jsort = <%out.print((sortmode.isEmpty())? "\"\"":sortmode);%>;
	var jmaxinpage = <%out.print(maxinpage);%>;
	var jmaxheight = new maxHeight(max);
	console.log(jmaxheight.value);
		setBodyDynamicScroll(jlast,jtag,jfilter,jsort,jmaxinpage,jmaxheight)
	</script>
<%@include file="footer.jsp"%>
